﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using BlueLotus7.Common;
using MongoDB.Bson.Serialization.Attributes;

namespace BlueLotus7.SSQAnalysisCore
{
    public class AnalysisResult : BaseBsonObject
    {
        #region Properties

        public string CatalogueIdentityStart
        {
            get;
            set;
        }

        public string CatalogueIdentityEnd
        {
            get;
            set;
        }

        public int TotalStageCount
        {
            get;
            set;
        }

        [BsonIgnore]
        public List<SSQMartixItem> SSQMartix
        {
            get;
            protected set;
        }

        public SSQLotteryData HitCount
        {
            get;
            protected set;
        }

        public SSQLotteryData OffsetCount
        {
            get;
            protected set;
        }

        public SSQLotteryData BasePercentage
        {
            get;
            protected set;
        }

        public List<BallCollection> CalculatedPercentage
        {
            get;
            protected set;
        }

        public BallMartix PRMartix
        {
            get;
            protected set;
        }

        public BallMartix Relevance
        {
            get;
            protected set;
        }

        public SSQLotteryData Result
        {
            get;
            protected set;
        }

        #endregion

        public AnalysisResult()
            : base()
        {
            this.SSQMartix = new List<SSQMartixItem>();
            this.HitCount = new SSQLotteryData();
            this.OffsetCount = new SSQLotteryData();
            this.BasePercentage = new SSQLotteryData();
            this.CalculatedPercentage = new List<BallCollection>();
            for (int i = 0; i <= 6; i++)
            {
                CalculatedPercentage.Add(new BallCollection(Constant.RedBallQuantity));
            }
            this.HitCount = new SSQLotteryData();
            this.PRMartix = new BallMartix(Constant.RedBallQuantity);
            this.Result = new SSQLotteryData();
            this.Relevance = new BallMartix(Constant.RedBallQuantity);
        }

        public void SetOffetCount(SSQMartixItem martix)
        {
            if (martix != null)
            {
                this.OffsetCount = martix as SSQLotteryData;
            }
        }

        public static string ExportToBinaryText(AnalysisResult analysisReport)
        {
            string result = string.Empty;

            if (analysisReport != null)
            {
                SerializeUtility serializer = new SerializeUtility();
                result = serializer.SerializeToBase64String(analysisReport);
            }

            return result;
        }

        public static AnalysisResult ImportFromBinaryText(string analysisReport)
        {
            object result = null;

            if (!string.IsNullOrWhiteSpace(analysisReport))
            {
                try
                {
                    SerializeUtility serializer = new SerializeUtility();
                    result = serializer.DerializeFromBase64String(analysisReport);
                }
                catch { }
            }

            return result as AnalysisResult;
        }
    }
}
